/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __AE37BA46_937B_48cd_8340_D38B540321E3__
#define __AE37BA46_937B_48cd_8340_D38B540321E3__

#include "../macro/head.h"
#include "../release/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 

namespace xos_box
{
    class i_big_buf;
    class i_list;
    class i_buf;
}

namespace xos
{
    // 
    // file interfacce
    // 
    class i_file : public i_release
    {
    public:
        // 
        // access defin
        // 
        enum enumFileAccessFlag
        {
            XOS_FILE_WRITE  = 0x01,
            XOS_FILE_READ   = 0x02
        };

        // 
        // file share define
        // 
        enum enumFileShareFlag
        {
            XOS_SHARE_WRITE  = 0x01,
            XOS_SHARE_READ   = 0x02
        };

        // 
        // file create type define
        // 
        enum enumFileOpenFlag
        {
            XOS_FILE_CREATE = 0x01,
            XOS_FILE_OPEN   = 0x02,
            XOS_FILE_TRUNC  = 0x04
        };

        // 
        // random move file pointer from ...
        // 
        enum enumFilePos
        {
            XOS_FILE_POS_BEGIN,
            XOS_FILE_POS_CUR,
            XOS_FILE_POS_END
        };

    protected:
        virtual ~i_file(){}

    public:
        //////////////////////////////////////////////////////////////////////////////////
        // 
        // open file
        // 
        virtual int open( const char * lpszFileName, uint32_t ulAccessFlag, uint32_t ulShareMode, uint32_t ulCreateFlag ) = 0;

        // 
        // get file time
        // 
        virtual int get_file_time( int64_t * lpCreateTime, int64_t * lpAccessTime, int64_t * lpModifyTime ) = 0;

        // 
        // get file or dir name
        // 
        virtual const char * get_file_name( char * lpszFileName, int nLen, int * pnLenNeeded ) = 0;

        // 
        // move file pointer to ...
        // 
        virtual int set_file_pos( enumFilePos enumFrom, int64_t iPos64, int64_t * lpSeek64 ) = 0;

        // 
        // get current file pointer
        // 
        virtual int get_file_pos( int64_t * lpSize64 ) = 0;

        // 
        // get file size
        // 
        virtual int get_file_size( int64_t * lpSize64 ) = 0;

        // 
        // commit file disk space.
        // 
        virtual int commit_file( int64_t iPos64 ) = 0;

        // 
        // write file data
        // 
        // -1 means failed. other , write bytes
        // 
        virtual int write( const void * lpBuf, uint32_t ulBufSize ) = 0;
        virtual int read( void * lpBuf, uint32_t ulBufSize ) = 0;

        // 
        // read file data
        // 
        // -1 means failed. other , read bytes
        // 
        virtual int write( xos_box::i_list * pList ) = 0;
        virtual int read( xos_box::i_list * pList ) = 0;
        virtual int write( xos_box::i_big_buf * pBuf ) = 0;
        virtual int read( xos_box::i_big_buf * pBuf ) = 0;
        virtual int write( xos_box::i_buf * pBuf ) = 0;
        virtual int read( xos_box::i_buf * pBuf ) = 0;

        // 
        // close file handle
        // 
        virtual int close() = 0;
    };
}

#endif // __AE37BA46_937B_48cd_8340_D38B540321E3__
